package com.itheima.canal.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class RabbiteMQConfig {
    //交换机名称
    private static final String GOODS_UP_EXCHANGE="goods_up_exchange";
    private static final String GOODS_PAGE_EXCHANGE="goods_page_exchange";
    private static final String GOODS_DOWN_EXCHANGE="goods_down_exchange";
    //定义队列名称
    public static final String AD_UPDATE_QUEUE="ad_update_queue";

    public static final String SEARCH_ADD_QUEUE="search_add_queue";

    public static final String SEARCH_DOWN_QUEUE="search_down_queue";

    public static final String GOODS_PAGE_QUEUE="goods_page_queue";

    //声明队列
    @Bean
    public Queue queue(){
        return new Queue(AD_UPDATE_QUEUE);
    }
    @Bean(SEARCH_ADD_QUEUE)
    public Queue SEARCH_ADD_QUEUE(){
        return new Queue(SEARCH_ADD_QUEUE);
    }

    @Bean(SEARCH_DOWN_QUEUE)
    public Queue SEARCH_DOWN_QUEUE(){
        return new Queue(SEARCH_DOWN_QUEUE);
    }

    @Bean(GOODS_PAGE_QUEUE)
    public Queue GOODS_PAGE_QUEUE(){
        return new Queue(GOODS_PAGE_QUEUE);
    }
    //声明交换机
    @Bean(GOODS_UP_EXCHANGE)
    public Exchange GOODS_UP_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_UP_EXCHANGE).durable(true).build();
    }

    @Bean(GOODS_DOWN_EXCHANGE)
    public Exchange GOODS_DOWN_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_DOWN_EXCHANGE).durable(true).build();
    }

    @Bean(GOODS_PAGE_EXCHANGE)
    public Exchange GOODS_PAGE_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_PAGE_EXCHANGE).durable(true).build();
    }
    //队列绑定交换机

    @Bean
    public Binding AD_UPDATE_QUEUE_BINDING(@Qualifier(SEARCH_ADD_QUEUE) Queue queue, @Qualifier(GOODS_UP_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();

    }

    @Bean
    public Binding DOWN_UPDATE_QUEUE_BINDING(@Qualifier(SEARCH_DOWN_QUEUE) Queue queue, @Qualifier(GOODS_DOWN_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
}
    @Bean
    public Binding PAGE_CREATE_QUEUE_BINDING(@Qualifier(GOODS_PAGE_QUEUE) Queue queue, @Qualifier(GOODS_PAGE_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();

    }
}

